<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<div id="app">
			<h2>{{fullname}}</h2>
			<button @click="setFullname">修改</button>
		</div>

		<script src="./js/vue.js"></script>
		<script>
			// 1. 创建app实例
			const app = Vue.createApp({
				data() {
					return {
						firstName: 'kobe',
						lastName: 'why',
					}
				},
				computed: {
					fullname: {
						get() {
							return this.lastName + ' ' + this.firstName
						},
						set(val) {
							const name = val.split(' ')
							this.firstName = name[1]
							this.lastName = name[0]
						},
					},
				},
				methods: {
					setFullname() {
						this.fullname = 'abc as'
					},
				},
			})

			// 2. 挂载到#app上
			app.mount('#app')
		</script>
	</body>
</html>
